/* button实例*/

#include "button.h"


struct Button btn1;
struct Button btn2;

uint8_t read_button1_GPIO() 
{
	return HAL_GPIO_ReadPin(GPIO_KEY1_PORT, GPIO_KEY1_PIN);
}

uint8_t read_button2_GPIO() 
{
	return HAL_GPIO_ReadPin(GPIO_KEY2_PORT,GPIO_KEY2_PIN);
}

void BTN1_PRESS_DOWN_Handler(void* btn)
{
	//do something...
	rt_kprintf("key1 down pressed!\n");
}

void BTN1_PRESS_UP_Handler(void* btn)
{
	//do something...
	rt_kprintf("key1 up pressed!\n");
}

void BTN1_PRESS_REPEAT_Handler(void* btn)
{
	//do something...
	rt_kprintf("key1 repeat pressed!\n");
}

void BTN1_SINGLE_Click_Handler(void* btn)
{
	
	rt_kprintf("key1 click pressed!\n");
   //当前产测模式失败
}

void BTN1_DOUBLE_Click_Handler(void* btn)
{
	//do something...
	rt_kprintf("key1 double click pressed!\n");
}

void BTN1_LONG_RRESS_START_Handler(void* btn)
{
	
	rt_kprintf("key1 long pressed!\n");
//  mcu_set_wifi_mode(0x00);
}

void BTN1_LONG_PRESS_HOLD_Handler(void* btn)
{
	//do something...
	rt_kprintf("key1 long hold pressed!\n");
}

void BTN2_PRESS_DOWN_Handler(void* btn)
{
	//do something...
	rt_kprintf("key2 down pressed!\n");
}

void BTN2_PRESS_UP_Handler(void* btn)
{
	//do something...
	rt_kprintf("key2 up pressed!\n");
}

void BTN2_PRESS_REPEAT_Handler(void* btn)
{
	//do something...
	rt_kprintf("key2 repeat pressed!\n");
}

void BTN2_SINGLE_Click_Handler(void* btn)
{
	
	rt_kprintf("key2 click pressed!\n");
   //当前产测模式失败
}

void BTN2_DOUBLE_Click_Handler(void* btn)
{
	//do something...
	rt_kprintf("key2 double click pressed!\n");
}

void BTN2_LONG_RRESS_START_Handler(void* btn)
{
//	toggleLED();
	rt_kprintf("key2 long pressed!\n");
  
}

void BTN2_LONG_PRESS_HOLD_Handler(void* btn)
{
	//do something...
	rt_kprintf("key2 long hold pressed!\n");
}

int btn_init()
{ 

	
	button_init(&btn1, read_button1_GPIO, 0);
	button_attach(&btn1, PRESS_DOWN,       BTN1_PRESS_DOWN_Handler);
	button_attach(&btn1, PRESS_UP,         BTN1_PRESS_UP_Handler);
	button_attach(&btn1, PRESS_REPEAT,     BTN1_PRESS_REPEAT_Handler);
	button_attach(&btn1, SINGLE_CLICK,     BTN1_SINGLE_Click_Handler);
	button_attach(&btn1, DOUBLE_CLICK,     BTN1_DOUBLE_Click_Handler);
	button_attach(&btn1, LONG_RRESS_START, BTN1_LONG_RRESS_START_Handler);
	button_attach(&btn1, LONG_PRESS_HOLD,  BTN1_LONG_PRESS_HOLD_Handler);
	button_start(&btn1);
	
	button_init(&btn2, read_button2_GPIO, 0);
	button_attach(&btn2, PRESS_DOWN,       BTN2_PRESS_DOWN_Handler);
	button_attach(&btn2, PRESS_UP,         BTN2_PRESS_UP_Handler);
	button_attach(&btn2, PRESS_REPEAT,     BTN2_PRESS_REPEAT_Handler);
	button_attach(&btn2, SINGLE_CLICK,     BTN2_SINGLE_Click_Handler);
	button_attach(&btn2, DOUBLE_CLICK,     BTN2_DOUBLE_Click_Handler);
	button_attach(&btn2, LONG_RRESS_START, BTN2_LONG_RRESS_START_Handler);
	button_attach(&btn2, LONG_PRESS_HOLD,  BTN2_LONG_PRESS_HOLD_Handler);
	button_start(&btn2);
	
	return(0);
}
